import hyRequest from '@/service'

// 用户的网络请求
export function postUserListData(queryInfo: any) {
  return hyRequest.post({
    url: '/users/list',
    data: queryInfo
  })
}

export function deleteUserById(id: number) {
  return hyRequest.delete({
    url: `/users/${id}`
  })
}

// 创建用户
export function createUser(userInfo: any) {
  return hyRequest.post({
    url: '/users',
    data: userInfo

    // 默认情况下为 json 提交
    // 若请求头设置为 application/x-www-form-urlencoded 则为表单提交(需要将对象传入到 data 属性中)
    // headers: { 'content-type': 'application/x-www-form-urlencoded' }
    // 传入到 params 中则为普通的 query 查询,参数以 ? 拼接在 URL 后
  })
}

// 编辑用户
export function updateUser(id: number, userInfo: any) {
  return hyRequest.patch({
    url: `/users/${id}`,
    data: userInfo
  })
}

export function postPageListData(pageName: string, queryInfo: any) {
  return hyRequest.post({
    url: `/${pageName}/list`,
    data: queryInfo
  })
}

export function deletePageById(pageName: string, id: number) {
  return hyRequest.delete({
    url: `/${pageName}/${id}`
  })
}

export function createPage(pageName: string, pageInfo: any) {
  return hyRequest.post({
    url: `/${pageName}`,
    data: pageInfo
  })
}

export function updatePage(pageName: string, id: number, pageInfo: any) {
  return hyRequest.patch({
    url: `/${pageName}/${id}`,
    data: pageInfo
  })
}
